package controller;
import model.*;
import java.util.ArrayList;
public class SellProductCtr
{
    private ProductCtr pc;
    private CustomerCtr cc;
    private Order o; 
    public SellProductCtr()
    {
        pc = new ProductCtr();
        cc = new CustomerCtr();
    }
    
    // gxg might need modification
    public boolean createOrder(String customerId)
    {
      
       CustomerContainer cCont = CustomerContainer.getInstance();
       OrderContainer oCont = OrderContainer.getInstance();
       Customer c = cCont.getCustomer(customerId);
       if(c!= null) 
       {
           o = new Order(c);
           oCont.addOrder(o);
           return true;
       }
       else return false;
       
    }
    
    public ArrayList<Order> findOrder(String customerId)
    {
        OrderContainer oCont = OrderContainer.getInstance();
        
        return oCont.findOrder(customerId);
       
    }
    
    public Order getOrder(String Id)
    {
        OrderContainer oCont = OrderContainer.getInstance();
        return oCont.getOrder(Id);
    }
    
    public boolean addProduct(String productSerial,int quantity)
    {
        ProductContainer pCont = ProductContainer.getInstance();
        Product p = pCont.getProduct(productSerial);
        if(p != null)
        {
            o.addOrderLine(p, quantity);
            return true;
        }
        else return false;
    }
    
    public double getTotal(String id)
    {
        return getOrder(id).getTotal();
    }
}